package com.biz.primus.app.rest.controller.member;

import com.biz.primus.app.rest.controller.base.RestBaseController;
import com.biz.primus.app.rest.feign.member.MemberFeignClient;
import com.biz.primus.base.support.rest.vo.JsonResult;
import com.biz.primus.base.global.GlobalParams;
import com.biz.primus.model.member.exception.UserExceptionResponse;
import com.biz.primus.model.member.exception.UserExceptionType;
import com.biz.primus.model.member.vo.PageVo;
import com.biz.primus.model.member.vo.request.BasePageableRequestVo;
import com.biz.primus.model.member.vo.request.BaseRequestVo;
import com.biz.primus.model.member.vo.request.DeleteFavouriteProductsRequestVo;
import com.biz.primus.model.member.vo.request.ProductCodeRequestVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户收藏相关Controller
 * @author jun.liu
 * @usage
 * @reviewer
 * @since 2017年11月3日
 */
@RestController
@RequestMapping("/users/favourite")
@Api(value = "会员收藏模块接口文档")
public class FavouriteController extends RestBaseController {

    private final MemberFeignClient memberFeignClient;

    @Autowired
    public FavouriteController(MemberFeignClient memberFeignClient) {
        this.memberFeignClient = memberFeignClient;
    }

    @ApiOperation(value = "添加收藏")
    @PostMapping("/add")
    @UserExceptionResponse({
            UserExceptionType.MEMBERID_NULL,UserExceptionType.FAVOURITE_PRODUCT_NULL
    })
    public JsonResult addFavourite(GlobalParams gp, @RequestBody ProductCodeRequestVo reqVo) {
        reqVo = buildRequest(gp, reqVo);
        memberFeignClient.addFavourite(reqVo);
        return new JsonResult();
    }

    @ApiOperation(value = "收藏列表", response = PageVo.class)
    @GetMapping("/list")
    @UserExceptionResponse({
            UserExceptionType.MEMBERID_NULL,UserExceptionType.FAVOURITE_NULL
    })
    public JsonResult favouriteList(GlobalParams gp, @RequestBody BasePageableRequestVo reqVo) {
        reqVo = buildRequest(gp, reqVo);
        PageVo resp = memberFeignClient.favouriteList(reqVo);
        return new JsonResult(resp);
    }

    @ApiOperation(value = "清空列表")
    @PostMapping("/clear")
    @UserExceptionResponse({
            UserExceptionType.MEMBERID_NULL,UserExceptionType.FAVOURITE_NULL
    })
    public JsonResult clearFavourite(GlobalParams gp) {
        BaseRequestVo reqVo = buildRequest(gp, new BaseRequestVo());
        memberFeignClient.clearFavourite(reqVo);
        return new JsonResult();
    }

    @ApiOperation(value = "批量删除收藏商品")
    @PostMapping("/delete")
    public JsonResult deleteFavourite(GlobalParams gp, @RequestBody DeleteFavouriteProductsRequestVo reqVo) {
        reqVo = buildRequest(gp, reqVo);
        memberFeignClient.deleteFavouriteProducts(reqVo);
        return new JsonResult();
    }

}
